package com.yxkj.syh.app.huarong.activities.orders_console;

import android.os.Bundle;
import android.widget.RadioGroup;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;

import com.syh.app.basic.base.BaseFragment;
import com.yxkj.syh.app.huarong.R;
import com.yxkj.syh.app.huarong.activities.orders.OrdersFragment;
import com.yxkj.syh.app.huarong.databinding.FragmentOrdersConsoleBinding;

/**
 * 订单控制台
 */
public class OrdersConsoleFragment extends BaseFragment<FragmentOrdersConsoleBinding, OrdersConsoleVM> {

    private BaseFragment mCurrentFragment;
    private OrdersFragment mOrdersFragment;

    public OrdersConsoleFragment() {
        // Required empty public constructor
    }

    public static OrdersConsoleFragment newInstance() {
        OrdersConsoleFragment fragment = new OrdersConsoleFragment();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected int getViewModelId() {
        return 0;
    }

    @Override
    protected int getContentLayout() {
        return R.layout.fragment_orders_console;
    }

    @Override
    protected void initView() {
        switchFragment(mOrdersFragment);
        mVDBinding.rgType.setOnCheckedChangeListener((group, checkedId) -> {
            if (checkedId == R.id.rbOrders) {//运单
                switchFragment(mOrdersFragment);
            } else if (checkedId == R.id.rbPayOrders) {//支出单

            }
        });
    }

    private void switchFragment(final BaseFragment targetFragment) {
        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        if (!targetFragment.isAdded()) {
            if (mCurrentFragment != null) {
                transaction.hide(mCurrentFragment);
            }
            transaction.add(R.id.flContent, targetFragment, targetFragment.getClass().getSimpleName());
        } else {
            if (targetFragment == mCurrentFragment) return;
            transaction.hide(mCurrentFragment);
            transaction.show(targetFragment);
        }
        mCurrentFragment = targetFragment;
        transaction.commit();
    }
}
